package com.orangelife.mobile.parkingcard.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;

import java.util.List;
import java.util.Map;

public class PrivateParkingListViewlAdapter<T> extends FatherAdapter<T> {

    private Context context;
    private List<Map<String, Object>> list;

    public PrivateParkingListViewlAdapter(Context context, List<Map<String, Object>> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings("unchecked")
    @Override
    public BaseAdapter setList(List<T> list) {
        this.list = (List<Map<String, Object>>) list;
        return PrivateParkingListViewlAdapter.this;
    }

    @SuppressWarnings("unchecked")
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_lv_private_parking, null);
            holder.tvPlateNumber = (TextView) convertView.findViewById(R.id.tvPlateNumber);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Map<String, Object> map = list.get(position);
        holder.tvPlateNumber.setText(map.get("num_plate").toString());
        return convertView;
    }


    class ViewHolder {
        TextView tvPlateNumber;
    }

}
